document.getElementById('uploadForm').addEventListener('submit', function(event) {
    event.preventDefault();

    let formData = new FormData();
    let pdfFile = document.getElementById('pdfInput').files[0];
    formData.append('pdf', pdfFile);

    fetch('/translate', {
        method: 'POST',
        body: formData
    })
        .then(response => response.blob())
        .then(translatedPDF => {
            let url = window.URL.createObjectURL(translatedPDF);
            let link = document.createElement('a');
            link.href = url;
            link.download = 'translated.pdf';
            link.click();
        })
        .catch(error => console.error('Error:', error));
});
